import { Component, OnInit } from '@angular/core';
import {Student} from '../student';
import {StudentService} from '../students.service';

@Component({
  selector: 'app-student',
  templateUrl: './student.component.html',
  styleUrls: ['./student.component.css']
})
export class StudentComponent implements OnInit {

  constructor( private studentService: StudentService) { }
  students: Student [] = [];
  display: Student[] = [];
  pageindex = 1;
  pagesize = 10;
  total = 10000;
  loading = false;
  changePageIndex(pageindex) {
    this.pageindex = pageindex ;
    this.display = this.students.slice(pageindex * 10 - 10, pageindex * 10);
  }

  getStudents(): void {
    this.loading = true;
    this.studentService.getStudents().subscribe(
      (res) => {
        res.data.forEach(row => {
          this.students = [...this.students];
          this.students.push( {
            native_place: row.native_place,
            time_of_enrollment: row.time_of_enrollment,
            birthday : row.birthday,
              class : row.class,
              major : row.major,
              name : row.name,
              sex : row.sex,
              stuid : row.stuid
            }
          );
        });
        this.display = this.students.slice( 0 , 10);
        this.loading = false;
      });
  }
  ngOnInit(): void {
    this.getStudents();
  }


}

